package com.just.sbweb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
//springboot1中是extents AbstractWebSocketMessageBrokerConfigurer，但是很不幸boot2中废除了
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    /**
     * 注册一个STOMP的endpoint,并使用SockJS协议
     * 添加一个服务端点，来接收客户端的连接
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("endpointYh").withSockJS();
        registry.addEndpoint("endpointChat").withSockJS();
    }

    /**
     * 广播式配置topic消息代理
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //客户端订阅地址的前缀信息
        registry.enableSimpleBroker("/queue","/topic");
        //客户端给服务端发消息地址的前缀
        //registry.setApplicationDestinationPrefixes("/web");
    }
}
